﻿using Liang.DataBase.Model.Entity;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;

namespace Liang.DataBase.Mapping.MySql
{
    public class RoleMap : EntityTypeConfiguration<sys_role>
    {
        public RoleMap()
        {
            // 表名
            this.ToTable("sys_role");

            // 主键
            this.HasKey(t => t.roleId);

            // 属性设置
            this.Property(t => t.roleId)
                .HasColumnName("roleId")
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            this.Property(t => t.name)
                .HasColumnName("name")
                .HasMaxLength(40)
                .IsRequired();

            this.Property(t => t.des)
                .HasColumnName("des")
                .HasMaxLength(120);

            // 关联关系
            this.HasMany(t => t.apps)
                .WithMany()
                .Map(m =>
                {
                    m.MapLeftKey("roleId");
                    m.MapRightKey("appId");
                    m.ToTable("sys_role_app");
                });
        }
    }
}
